package com.area.cth.controller;

import com.area.cth.mapper.UserRoleMapper;
import com.area.cth.common.Result;
import com.area.cth.pojo.UserRole;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "用户角色关系相关接口")
@RestController
@RequestMapping("/userRole")
@CrossOrigin
public class UserRoleController {
    @Autowired
    private UserRoleMapper userRoleMapper;

    @Operation(summary = "新增用户角色关系")
    @PostMapping
    public Result addDeal(@RequestBody @Validated UserRole userRole) {
        userRoleMapper.insert(userRole);
        return Result.success();
    }

    @Operation(summary = "查询用户角色关系")
    @GetMapping
    public Result<List<UserRole>> getUserRoleList() {
        List<UserRole> urs = userRoleMapper.selectList(null);
        return Result.success(urs);
    }

    @Operation(summary = "修改用户角色关系")
    @PutMapping
    public Result update(@RequestBody @Validated UserRole uR) {
        userRoleMapper.updateById(uR);
        return Result.success();
    }

    @Operation(summary = "删除用户角色关系")
    @DeleteMapping
    public Result delete(Integer id) {
        userRoleMapper.deleteById(id);
        return new Result(0,"删除成功",null);
    }
}
